﻿<div ng-controller="Report_DebtC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">应收账款报表</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <a class="btn btn-sm btn-default" href="/api/Report/ExpDebtReport?settlementTime={{settlementTime.format('yyyy-MM-dd')}}">
                        <i class="fa fa-plus text"></i>
                        <span class="text">全部导出</span>
                    </a>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group">
                    <input type="date" class="form-control" placeholder="查询日期" ng-model="settlementTime">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                    </span>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light table-bordered">
                    <thead>
                        <tr>
                            <th style="text-align: center;" ng-repeat="item in newreports[0] track by $index">{{item}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="ord in reports track by $index">
                            <td class="text-center" ng-repeat="item in ord track by $index">{{item}}</td>
                        </tr>
                    </tbody>
                </table>
                <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')
            .controller("Report_DebtC", function ($scope, $state, $http,toSave) {
                $scope.pageData = {};
                $scope.pageData.Page = 0;
                $scope.settlementTime = null;
                $scope.pageData.Rows = $scope.defPageRows;
                $scope.getData = function (p, r) {
                    if (p) {
                        p = p < 1 ? 1 : p;
                    } else p = 1;
                    if (r) {
                    } else r = $scope.defPageRows;
                    toSave.save_pages_lis(p,r);//保存当前页码和条数
                    console.log(toSave.get_pages(), $scope.pageData.Rows)
                    $http.get("../api/Report/DebtReport", { params: { page: p, rows:  $scope.pageData.Rows, settlementTime: $scope.settlementTime, isHand: true } }).then(function (res) {
                                $scope.reports = res.data.Data;
                                $scope.newreports = $scope.reports.splice(0, 1);
                                $scope.pageData = res.data;  console.log(toSave.get_pages(), $scope.pageData.Rows);
                            })
                            .then(function (error) {
                                if (error) {
                                    alert("数据获取失败");
                                }
                            });
                };
                $scope.find = function () {
                    console.log($scope.settlementTime);
                    $scope.getData(1, $scope.rows);
                };
                //加载数据
                $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
            })
</script>
<script src="js/services/toSave.js"></script>
